<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
        <title>redis安装和启动 - 豆是不吃豆豉</title><meta name="Description" content="豆是不吃豆豉"><meta property="og:title" content="redis安装和启动" />
<meta property="og:description" content="redis简介 redis是一个BSD开源的高性能(key/value)分布式内存数据库，并支持持久化。 redis安装(centos7) 官网下" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://dou-chi.gitee.io/redis%E5%AE%89%E8%A3%85%E5%92%8C%E5%90%AF%E5%8A%A8/" />
<meta property="og:image" content="https://dou-chi.gitee.io/logo.png"/>
<meta property="article:published_time" content="2019-12-13T14:59:51+00:00" />
<meta property="article:modified_time" content="2019-12-13T14:59:51+00:00" />
<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://dou-chi.gitee.io/logo.png"/>

<meta name="twitter:title" content="redis安装和启动"/>
<meta name="twitter:description" content="redis简介 redis是一个BSD开源的高性能(key/value)分布式内存数据库，并支持持久化。 redis安装(centos7) 官网下"/>
<meta name="application-name" content="豆是不吃豆豉">
<meta name="apple-mobile-web-app-title" content="豆是不吃豆豉"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
        <link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
        <link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png"><link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png"><link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5"><link rel="manifest" href="/site.webmanifest"><link rel="canonical" href="https://dou-chi.gitee.io/redis%E5%AE%89%E8%A3%85%E5%92%8C%E5%90%AF%E5%8A%A8/" /><link rel="next" href="https://dou-chi.gitee.io/redis%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E5%92%8C%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/" /><link rel="stylesheet" href="/lib/normalize/normalize.min.css"><link rel="stylesheet" href="/css/style.min.css"><link rel="stylesheet" href="/lib/fontawesome-free/all.min.css"><link rel="stylesheet" href="/lib/animate/animate.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "redis安装和启动",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/dou-chi.gitee.io\/redis%E5%AE%89%E8%A3%85%E5%92%8C%E5%90%AF%E5%8A%A8\/"
        },"genre": "posts","keywords": "redis, redis安装","wordcount":  631 ,
        "url": "https:\/\/dou-chi.gitee.io\/redis%E5%AE%89%E8%A3%85%E5%92%8C%E5%90%AF%E5%8A%A8\/","datePublished": "2019-12-13T14:59:51+00:00","dateModified": "2019-12-13T14:59:51+00:00","publisher": {
            "@type": "Organization",
            "name": ""},"author": {
                "@type": "Person",
                "name": "豆是不吃豆豉"
            },"description": ""
    }
    </script></head>
    <body header-desktop="fixed" header-mobile="auto"><script type="text/javascript">(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('dark' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'dark' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="豆是不吃豆豉">豆是不吃豆豉</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 所有文章 </a><a class="menu-item" href="/tags/"> 标签 </a><a class="menu-item" href="/categories/"> 分类 </a><a class="menu-item" href="https://github.com/dou-chi" rel="noopener noreffer" target="_blank"> github </a><a class="menu-item" href="https://gitee.com/dou-chi" rel="noopener noreffer" target="_blank"> gitee </a><span class="menu-item delimiter"></span><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-desktop">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-desktop" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-desktop" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="豆是不吃豆豉">豆是不吃豆豉</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-mobile">
                        <a href="javascript:void(0);" class="search-button search-toggle" id="search-toggle-mobile" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="javascript:void(0);" class="search-button search-clear" id="search-clear-mobile" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </div>
                    <a href="javascript:void(0);" class="search-cancel" id="search-cancel-mobile">
                        取消
                    </a>
                </div><a class="menu-item" href="/posts/" title="">所有文章</a><a class="menu-item" href="/tags/" title="">标签</a><a class="menu-item" href="/categories/" title="">分类</a><a class="menu-item" href="https://github.com/dou-chi" title="" rel="noopener noreffer" target="_blank">github</a><a class="menu-item" href="https://gitee.com/dou-chi" title="" rel="noopener noreffer" target="_blank">gitee</a><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                <i class="fas fa-adjust fa-fw"></i>
            </a></div>
    </div>
</header>
<div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div>
<main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content always-active" id="toc-content-auto"></div>
        </div><article class="page single"><h1 class="single-title animated flipInX">redis安装和启动</h1><div class="post-meta">
            <div class="post-meta-line"><span class="post-author"><a href="/" title="Author" rel=" author" class="author"><i class="fas fa-user-circle fa-fw"></i>豆是不吃豆豉</a></span>&nbsp;<span class="post-category">收录于 <a href="/categories/redis/"><i class="far fa-folder fa-fw"></i>redis</a></span></div>
            <div class="post-meta-line"><i class="far fa-calendar-alt fa-fw"></i>&nbsp;<time datetime="2019-12-13">2019-12-13</time>&nbsp;<i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 631 字&nbsp;
                <i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 2 分钟&nbsp;</div>
        </div><div class="details toc" id="toc-static"  kept="">
                <div class="details-summary toc-title">
                    <span>目录</span>
                    <span><i class="details-icon fas fa-angle-right"></i></span>
                </div>
                <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li>
      <ul>
        <li><a href="#redis简介">redis简介</a></li>
        <li><a href="#redis安装centos7">redis安装(centos7)</a></li>
        <li><a href="#redis启动">redis启动</a></li>
        <li><a href="#redis关闭">redis关闭</a></li>
        <li><a href="#简要描述">简要描述</a></li>
      </ul>
    </li>
  </ul>
</nav></div>
            </div><div class="content" id="content"><h2 id="redis简介">redis简介</h2>
<p>redis是一个BSD开源的高性能(key/value)分布式<code>内存</code>数据库，并支持持久化。</p>
<!-- more -->
<h2 id="redis安装centos7">redis安装(centos7)</h2>
<p>官网下载地址：<a href="https://redis.io/download" title="https://redis.io/download" target="_blank" rel="noopener noreffer">https://redis.io/download</a>
可以直接输入命令直接下载并解压,安装在opt目录下</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-shell" data-lang="shell"><span class="nb">cd</span> /opt
wget http://download.redis.io/releases/redis-5.0.5.tar.gz
tar xzf redis-5.0.5.tar.gz
<span class="nb">cd</span> redis-5.0.5
</code></pre></td></tr></table>
</div>
</div><p>执行<code>make</code>命令，如果出现gcc错误，则说明该系统没有安装gcc(GNU Compiler Collection是C程序的编译工具)，此时执行命令</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-shell" data-lang="shell">yum install gcc-c++
</code></pre></td></tr></table>
</div>
</div><p>安装完成之后再次执行<code>make</code>命令，如果出现<code>jemalloc/jemalloc.h：没有那个文件或目录</code>则需要运行<code>make distclean</code>之后再<code>make</code>，redis默认会安装到<code>/usr/local/bin</code>目录下。</p>
<h2 id="redis启动">redis启动</h2>
<p>进入到redis解压目录，可以新建一个myredis文件夹，复制redis.conf（备份）配置文件到myredis文件夹中，修改配置文件中 <strong>GENERAL 下的 daemonize 为 yes</strong> ，表示后台运行。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-shell" data-lang="shell">mkdir myredis
cp redis.conf /opt/myredis
vi /myredis/redis.conf
</code></pre></td></tr></table>
</div>
</div><p>进入到<code>/usr/local/bin</code>目录下启动redis服务。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-shell" data-lang="shell"><span class="nb">cd</span> /usr/local/bin
redis-server /myredis/redis.conf
</code></pre></td></tr></table>
</div>
</div><p>检测是否启动成功。</p>
<div class="highlight"><div class="chroma">
<table class="lntable"><tr><td class="lntd">
<pre class="chroma"><code><span class="lnt">1
</span><span class="lnt">2
</span><span class="lnt">3
</span><span class="lnt">4
</span></code></pre></td>
<td class="lntd">
<pre class="chroma"><code class="language-shell" data-lang="shell">redis-cli -p <span class="m">6379</span>
127.0.0.1:6379&gt; ping
PONG
127.0.0.1:6379&gt;
</code></pre></td></tr></table>
</div>
</div><p>可以使用 <strong>redis-benchmark</strong> 做个简单的压测，直接执行 <code>redis-benchmark</code>即可</p>
<h2 id="redis关闭">redis关闭</h2>
<ol>
<li>单实例关闭：redis-cli shutdown</li>
<li>多实例关闭，指定端口关闭:redis-cli -p 6379 shutdown</li>
</ol>
<h2 id="简要描述">简要描述</h2>
<p><a href="http://redisdoc.com/" title="redis常用命令查询" target="_blank" rel="noopener noreffer">redis常用命令查询</a>
redis默认是16个数据库，下标从0开始，初始默认使用0号库。
<code>select</code> 命令切换数据库
<code>dbsize</code> 查看当前数据库的key的数量
<code>flushdb</code> 清空当前库
<code>Flushall</code> 清空全部库</p>
</div><div class="post-footer" id="post-footer">
    <div class="post-info">
        <div class="post-info-line">
            <div class="post-info-mod">
                <span>更新于 2019-12-13</span>
            </div>
            <div class="post-info-license"></div>
        </div>
        <div class="post-info-line">
            <div class="post-info-md"><span>
                            <a class="link-to-markdown" href="/redis%E5%AE%89%E8%A3%85%E5%92%8C%E5%90%AF%E5%8A%A8/index.md" target="_blank">阅读原始文档</a>
                        </span></div>
            <div class="post-info-share">
                <span><a href="javascript:void(0);" title="分享到 Twitter" data-sharer="twitter" data-url="https://dou-chi.gitee.io/redis%E5%AE%89%E8%A3%85%E5%92%8C%E5%90%AF%E5%8A%A8/" data-title="redis安装和启动" data-hashtags="redis,redis安装"><i class="fab fa-twitter fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Facebook" data-sharer="facebook" data-url="https://dou-chi.gitee.io/redis%E5%AE%89%E8%A3%85%E5%92%8C%E5%90%AF%E5%8A%A8/" data-hashtag="redis"><i class="fab fa-facebook-square fa-fw"></i></a><a href="javascript:void(0);" title="分享到 WhatsApp" data-sharer="whatsapp" data-url="https://dou-chi.gitee.io/redis%E5%AE%89%E8%A3%85%E5%92%8C%E5%90%AF%E5%8A%A8/" data-title="redis安装和启动" data-web><i class="fab fa-whatsapp fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Line" data-sharer="line" data-url="https://dou-chi.gitee.io/redis%E5%AE%89%E8%A3%85%E5%92%8C%E5%90%AF%E5%8A%A8/" data-title="redis安装和启动"><i data-svg-src="/lib/simple-icons/icons/line.min.svg"></i></a><a href="javascript:void(0);" title="分享到 微博" data-sharer="weibo" data-url="https://dou-chi.gitee.io/redis%E5%AE%89%E8%A3%85%E5%92%8C%E5%90%AF%E5%8A%A8/" data-title="redis安装和启动"><i class="fab fa-weibo fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Myspace" data-sharer="myspace" data-url="https://dou-chi.gitee.io/redis%E5%AE%89%E8%A3%85%E5%92%8C%E5%90%AF%E5%8A%A8/" data-title="redis安装和启动" data-description=""><i data-svg-src="/lib/simple-icons/icons/myspace.min.svg"></i></a><a href="javascript:void(0);" title="分享到 Blogger" data-sharer="blogger" data-url="https://dou-chi.gitee.io/redis%E5%AE%89%E8%A3%85%E5%92%8C%E5%90%AF%E5%8A%A8/" data-title="redis安装和启动" data-description=""><i class="fab fa-blogger fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Evernote" data-sharer="evernote" data-url="https://dou-chi.gitee.io/redis%E5%AE%89%E8%A3%85%E5%92%8C%E5%90%AF%E5%8A%A8/" data-title="redis安装和启动"><i class="fab fa-evernote fa-fw"></i></a></span>
            </div>
        </div>
    </div>

    <div class="post-info-more">
        <section class="post-tags"><i class="fas fa-tags fa-fw"></i>&nbsp;<a href="/tags/redis/">redis</a>,&nbsp;<a href="/tags/redis%E5%AE%89%E8%A3%85/">redis安装</a></section>
        <section>
            <span><a href="javascript:void(0);" onclick="window.history.back();">返回</a></span>&nbsp;|&nbsp;<span><a href="/">主页</a></span>
        </section>
    </div>

    <div class="post-nav">
            <a href="/redis%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B%E5%92%8C%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4/" class="next" rel="next" title="redis数据类型和常用命令">redis数据类型和常用命令<i class="fas fa-angle-right fa-fw"></i></a></div>
</div>
<div id="comments"></div></article></div>
            </main><footer class="footer">
        <div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.74.3">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/dillonzq/LoveIt" target="_blank" rel="noopener noreffer" title="LoveIt 0.2.10"><i class="far fa-kiss-wink-heart fa-fw"></i> LoveIt</a>
                </div><div class="footer-line"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2019 - 2021</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="/" target="_blank">豆是不吃豆豉</a></span></div>
        </div>
    </footer></div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-arrow-up fa-fw"></i>
            </a><a href="#" id="view-comments" class="fixed-button" title="查看评论">
                <i class="fas fa-comment fa-fw"></i>
            </a>
        </div><link rel="stylesheet" href="/lib/katex/katex.min.css"><link rel="stylesheet" href="/lib/katex/copy-tex.min.css"><link rel="stylesheet" href="/lib/cookieconsent/cookieconsent.min.css"><script type="text/javascript" src="/lib/smooth-scroll/smooth-scroll.min.js"></script><script type="text/javascript" src="/lib/autocomplete/autocomplete.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.stemmer.support.min.js"></script><script type="text/javascript" src="/lib/lunr/lunr.zh.min.js"></script><script type="text/javascript" src="/lib/lazysizes/lazysizes.min.js"></script><script type="text/javascript" src="/lib/clipboard/clipboard.min.js"></script><script type="text/javascript" src="/lib/sharer/sharer.min.js"></script><script type="text/javascript" src="/lib/katex/katex.min.js"></script><script type="text/javascript" src="/lib/katex/auto-render.min.js"></script><script type="text/javascript" src="/lib/katex/copy-tex.min.js"></script><script type="text/javascript" src="/lib/katex/mhchem.min.js"></script><script type="text/javascript" src="/lib/cookieconsent/cookieconsent.min.js"></script><script type="text/javascript">window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":100},"comment":{},"cookieconsent":{"content":{"dismiss":"同意","link":"了解更多","message":"本网站使用 Cookies 来改善您的浏览体验."},"enable":true,"palette":{"button":{"background":"#f0f0f0"},"popup":{"background":"#1aa3ff"}},"theme":"edgeless"},"math":{"delimiters":[{"display":true,"left":"$$","right":"$$"},{"display":true,"left":"\\[","right":"\\]"},{"display":false,"left":"$","right":"$"},{"display":false,"left":"\\(","right":"\\)"}],"strict":false},"search":{"highlightTag":"em","lunrIndexURL":"/index.json","lunrLanguageCode":"zh","lunrSegmentitURL":"/lib/lunr/lunr.segmentit.js","maxResultLength":10,"noResultsFound":"没有找到结果","snippetLength":50,"type":"lunr"}};</script><script type="text/javascript" src="/js/theme.min.js"></script></body>
</html>
